/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * pnfEstadoActualAlmacen.java
 *
 * Created on 09/11/2011, 04:42:17 PM
 */

package visual.Configuracion;

import blogic.*;
import bentity.*;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferStrategy;
import java.sql.SQLException;
import java.util.ArrayList;
import visual.*;
import visual.Seguridad.visualHelper;

/**
 *
 * @author giulio
 */
public class pnfEstadoActualAlmacen extends javax.swing.JPanel {
    private static final int TAM_UNIT = 10;
    private int racksXCol = 0;
    private int racksXFila = 0;
    private int tamRack = 0;
    private boolean esPrimeraVez=false;
    private boolean pintaEnt=false;
    private Point puntoCentrado= new Point();
    private Point entrada = new Point(-1,-1);
    private ArrayList pedidos = new ArrayList<Point>();
    private ArrayList<beRack> racks=new ArrayList<beRack>();
    private ArrayList entradas=new ArrayList<beEntrada>();
    ArrayList<beUbicacion> ubicaciones = new ArrayList<beUbicacion>();
    private char[][] matriz;
    private boolean eligio_entrada=false;
    private BufferStrategy bfs=null;
    private beAlmacen alma=new beAlmacen();
    /** Creates new form pnfEstadoActualAlmacen */
    public pnfEstadoActualAlmacen() {
            super();
            initComponents();
            blAlmacen bla= new blAlmacen();
            blHelper blh =new blHelper();
            blRack blr= new blRack();
            try {
                alma=blh.obtenerDatosAlmacen();
                entradas = bla.buscarObjsEntrada();
                racks = blr.obtenerRacksConSecs();
            } catch (SQLException ex) {
                ex.printStackTrace();
                visualHelper.mostrarMensajeError("Ocurrió un error durante el procesamiento");
            }
            
            try {
                    racks = blr.obtenerRacksConSecs();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                    visualHelper.mostrarMensajeError("Ocurrió un error durante el proceso");
                }
            racksXCol=alma.getFilas();
            racksXFila=alma.getRacksXFila();
            tamRack=alma.getUbsxrack();
            
            
            
            puntoCentrado=visualHelper.centrarDibujo(this.getSize(), blh.calcularNumeroColumnas(racksXFila, tamRack),blh.calcularNumeroFilas(racksXCol) , TAM_UNIT);
            this.repaint();
    }

    @Override
	    public void paint(Graphics g){
                if (!this.esPrimeraVez){
                    this.esPrimeraVez=true;
                    //this.createBufferStrategy(2);
                    //bfs =this.getBufferStrategy();
                }

                //if (getBfs()!=null){
                    //Graphics g1=getBfs().getDrawGraphics();
                    super.paint(g);
                    visualHelper.pintarAlmacenConEntradasSecciones(g,entradas, racksXCol, racksXFila, tamRack, TAM_UNIT,racks, this.getSize(),null, false);
                    visualHelper.pintarMalla(g, racksXCol, racksXFila, tamRack, TAM_UNIT,  this.getSize());
                    visualHelper.pintarRotulosPasillosRacksFilas(g, racksXCol, racksXFila, tamRack, this.TAM_UNIT, this.getSize());
                    //getBfs().show();
                //}
	    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblNumUbics1 = new javax.swing.JLabel();
        pnlEstadosUbicacion = new javax.swing.JPanel();
        lblTipoPallet1 = new javax.swing.JLabel();
        lblNoDisponibles = new javax.swing.JLabel();
        lblUbicacionesLibres = new javax.swing.JLabel();
        pnlVerde = new javax.swing.JPanel();
        pnlAzul = new javax.swing.JPanel();

        setAutoscrolls(true);

        lblNumUbics1.setFont(new java.awt.Font("Dialog", 0, 36));
        lblNumUbics1.setText("Estado actual del almacén");

        pnlEstadosUbicacion.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Leyenda", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Dialog", 0, 14))); // NOI18N
        pnlEstadosUbicacion.setLayout(null);

        lblTipoPallet1.setFont(new java.awt.Font("Dialog", 0, 12));
        lblTipoPallet1.setForeground(new java.awt.Color(0, 0, 0));
        lblTipoPallet1.setText("Pallet");
        pnlEstadosUbicacion.add(lblTipoPallet1);
        lblTipoPallet1.setBounds(340, 492, 80, 15);

        lblNoDisponibles.setFont(new java.awt.Font("Dialog", 0, 12));
        lblNoDisponibles.setForeground(new java.awt.Color(0, 0, 0));
        lblNoDisponibles.setText("Racks con sección asignada");
        pnlEstadosUbicacion.add(lblNoDisponibles);
        lblNoDisponibles.setBounds(40, 10, 220, 30);

        lblUbicacionesLibres.setFont(new java.awt.Font("Dialog", 0, 12));
        lblUbicacionesLibres.setForeground(new java.awt.Color(0, 0, 0));
        lblUbicacionesLibres.setText("Racks sin sección asignada");
        pnlEstadosUbicacion.add(lblUbicacionesLibres);
        lblUbicacionesLibres.setBounds(40, 30, 220, 30);

        pnlVerde.setBackground(java.awt.Color.green);
        pnlVerde.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlEstadosUbicacion.add(pnlVerde);
        pnlVerde.setBounds(20, 40, 12, 12);

        pnlAzul.setBackground(java.awt.Color.blue);
        pnlAzul.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        pnlEstadosUbicacion.add(pnlAzul);
        pnlAzul.setBounds(20, 20, 12, 12);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(357, 357, 357)
                        .addComponent(lblNumUbics1, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(285, 285, 285)
                        .addComponent(pnlEstadosUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(377, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNumUbics1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlEstadosUbicacion, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(309, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblNoDisponibles;
    private javax.swing.JLabel lblNumUbics1;
    private javax.swing.JLabel lblTipoPallet1;
    private javax.swing.JLabel lblUbicacionesLibres;
    private javax.swing.JPanel pnlAzul;
    private javax.swing.JPanel pnlEstadosUbicacion;
    private javax.swing.JPanel pnlVerde;
    // End of variables declaration//GEN-END:variables

}
